package Solution.problem078.Subsets;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/06/28 09:49
 */
public class BetterSolution {

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        Arrays.sort(nums);
        backtracking(result, nums, list, 0);
        return result;
    }

    private void backtracking(List<List<Integer>> result, int nums[], List<Integer> list, int start) {
        result.add(new ArrayList<>(list));
        for (int i = start; i < nums.length; i++) {
            list.add(nums[i]);
            backtracking(result, nums, list, i + 1);
            list.remove(list.size() - 1);

        }
    }
}
